﻿#region
/*************************************************************************************
     * CLR 版本：       4.0.30319.18444
     * 类 名 称：       CJClient
     * 机器名称：       YANG-PC
     * 命名空间：       SSO
     * 文 件 名：       CJClient
     * 创建时间：       2015/4/17 15:57:25
     * 计算机名：       Yang
     * 作    者：       Jason.Yang(yangxing1002@gmail.com)
     * 说    明： 
     * 修改时间：
     * 修 改 人：
**************************************************************************************/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace CJAtech.BBS.Process
{
    public class CJClient
    {

        public const string FORMAT = "format";
        public const string METHOD = "method";
        public const string TIMESTAMP = "timestamp";
        public const string VERSION = "v";
        public const string SIGN = "sign";
        public const string PARTNER_ID = "partner_id";
        public const string SESSION = "token";
        public const string FORMAT_XML = "xml";
        public const string SDK_VERSION = "0000"; // SDK自动生成会替换成真实的版本

        public const string OPEN_ID = "openId";
        public const string CALL_BACK = "callback";
        public const string PROJECT_CODE = "projectCode";
        public const string AVATAR = "avatar";
        public const string AUTH_TYPE = "auth_type";
        public const string SESSION_LOGININFO_KEY = "__LoginInfo";

        private string serverUrl;
        private string appKey;
        private string appSecret;
        private string format = FORMAT_XML;

        public string BuildAuthUrl(string url, string openId, string secret, string callback, Dictionary<string, string> txtParams, DateTime timestamp)
        {
            txtParams.Add(CALL_BACK, callback);
            txtParams.Add(VERSION, "1.0");
            txtParams.Add(OPEN_ID, openId);
            txtParams.Add(FORMAT, format);
            txtParams.Add(PARTNER_ID, SDK_VERSION);
            //txtParams.Add(TIMESTAMP, timestamp.ToString());
            // txtParams.Add(SESSION, session);
            // txtParams.AddAll(this.systemParameters);

            // 添加签名参数
            txtParams.Add(SIGN, CJUtils.SignRequest(txtParams, secret));
            var webUtils = new WebUtils();
            return webUtils.BuildGetUrl(url, txtParams);
        }
    }
}
